<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class C_Slide extends CI_Controller {

 function __construct()
 {
	parent::__construct();

    $this->load->model('m_impact', '', true);	
 }
 function index($offset = ''){
	$data['slides'] =	$this->m_impact->get_by_sql('SELECT * FROM  tbl_slide ORDER BY id DESC');	 	
	$data['body'] ='slide/v_slide_list';
	$this->load->view('desktop/desktop',$data);
 }
 
 /*
 show page new
 */
 function page_new(){
	$data['body']='slide/v_page_new';
	$this->load->view('desktop/desktop',$data);
 }
 /*
 Insert data to DB
 */
 function save_new ($type = FALSE){ 
	
	$data_arr = array(
						'name'			=> $this->input->post('name'), 
						'image' 		=> $this->input->post('image'), 
						'user_create' 	=> $this->session->userdata('name'), 
	 				    'create_date' 	=> date('Y-m-d H:i:s')  
					 );
	 $result =	$this->m_impact->insert('tbl_slide', $data_arr, '');
	 if($result){
		 $this->session->set_userdata('message', $this->connect->message("Slide has been created!", "success"));
	 }else{
		 $this->session->set_userdata('message', $this->connect->message("Slide has been created with error!", "warning"));
	 }
	 
	 redirect(site_url().'/c_slide/page_new', 'location', 302);
 }
 /*
 page edit
 */
 function page_edit($id = false){
	 $id = $this->m_impact->encrypt_decrypt('decrypt', $id);

	 $where = array('id' => $id);
	 $data['slides']	=	array_shift($this->m_impact->get_by_fields('tbl_slide',$where,'id'));
	 
	 $data['body']='slide/v_page_edit';
	 $this->load->view('desktop/desktop',$data);
 }
 
 /*
 page update data
 */
 function update(){
	$id = $this->m_impact->encrypt_decrypt('decrypt', $this->input->post('id'));
	$where	= array('id' => $id);
	$data_arr = array(
						'name'			=> $this->input->post('name'), 
						'image' 		=> $this->input->post('image'), 
						'user_update' 	=> $this->session->userdata('name'), 
	 				    'update_date' 	=> date('Y-m-d H:i:s')  
					 );
	$result	=	$this->m_impact->update_field('tbl_slide', $data_arr, $where);
	
	if($result){
		$this->session->set_userdata('message', $this->connect->message("Slide has been updated!", "success"));
	}else{
		$this->session->set_userdata('message', $this->connect->message("Slide has been updated with error!", "warning"));
	}

	redirect(site_url().'/c_slide', 'location', 302);
 }
 
 /*
 page update data
 */
 function delete($id, $image){
	$id = $this->m_impact->encrypt_decrypt('decrypt', $id);
	
	$where = array('id' => $id);
	if($image)
	   unlink('./upload/slides/'.$image);
	
	$result	=	$this->m_impact->delete('tbl_slide', $where);
	if($result){
	   $this->session->set_userdata('message', $this->connect->message("Slide has been delete!", "success"));
	}else{
	   $this->session->set_userdata('message', $this->connect->message("Error delete slide!", "warning"));
	} 
	
	redirect(site_url().'/c_slide', 'location', 302);
 }
 
}
// end c_promotion

?>
